package com.sky.task;

import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class OrderTask {
    @Autowired
    private OrderMapper orderMapper;
    /**
     * 处理超时订单，用户未支付
     * 每分钟进行一次查询
     */
    @Scheduled(cron = "0 * * * * *")
    public void processTimeOutOrder() {
        log.info("超时订单定时处理 {}", LocalDateTime.now());
        LocalDateTime now = LocalDateTime.now().plusMinutes(-15);
        orderMapper.cancelByTime(now);
    }
    @Scheduled(cron = "0 0 1 * * ?")
    public void processOrderDelivery() {
        log.info("派送中订单处理 {}", LocalDateTime.now());
        LocalDateTime now = LocalDateTime.now().plusMinutes(-60);
        orderMapper.completeByTime(now);
    }
}
